// Wastepile.cpp: implementation of the CWastepile class.
//
//////////////////////////////////////////////////////////////////////

#include "iface.h"
#include "Wastepile.h"


extern int ShowCards;

const char* CWastepile::SlotName()
{
	return "Wastepile";
}
CWastepile::CWastepile() 
{

}

CWastepile::~CWastepile()
{

}

bool CWastepile::CheckPushPrecondition(const CCard &_card)
{
	if( false == CSlot::CheckPushPrecondition( _card ) ) return false;

	if( _card.IsFaceDown() ) return false;

	return true;
}

#define SPACE_OPEN 15

void CWastepile::CalculateDrawingArea( int& _x, int&  _y, int& _width, int& _height )
{
	// max 3 open 

	
	_width = 3 * SPACE_OPEN + CARD_WIDTH;
	_height = CARD_HEIGHT;
	
}

void CWastepile::Draw(unsigned int _x, unsigned int _y, bool selected )
{
	unsigned char i = 0;

	ClearDrawingArea(_x, _y);
	
	if( this->cards_stored )
	{
		for( ; i < cards_stored ; i++ )
		{
			unsigned char modificator = ( (i%ShowCards)?(i%ShowCards):0 );
			cardstack[i].Draw( _x + ( 15 * modificator ), _y );
		}
	}
	else
	{
		CCard::DrawPlaceHolder( _x, _y );
	}

		/* draw hand */

	if( selected )
	{
		if( 0 == this->cards_stored )
			CCard::DrawCursor( _x + 20, _y+10 );
		else
			CCard::DrawCursor( _x + ( 15 * ( ((i-1)%ShowCards)?((i-1)%ShowCards):0 ) ) + 20, _y+10 );
	}
}

bool CWastepile::IncreaseSelection()
{
	if( cards_stored && 0 == cards_selected )
	{
		cards_selected = 1;
		return true;
	}
	else
		return false;
}


